import {
  AccountParams,
  DeptParams,
  MenuParams,
  RoleParams,
  InterfacePageParams,
  InterfaceParams,
  RolePageParams,
  MenuListItem,
  DeptListItem,
  InterfaceListItem,
  MenuListGetResultModel,
  DeptListGetResultModel,
  AccountListGetResultModel,
  RolePageListGetResultModel,
  InterfacePageListGetResultModel,
  InterfaceCatePageListGetResultModel,
  InterfaceCateParams,
  InterfaceListGetResultModel,
  RoleListGetResultModel,
  InterfaceCateListGetResultModel,
} from './model/authModel';
import { defHttp } from '/@/utils/http/axios';

enum Api {
  //账户相关
  AccountList = '/sys/user/account/page',
  AccountRestFul = '/sys/user/account',

  //角色相关
  RoleRestful = '/sys/role',
  GetAllRoleList = '/sys/role/list',
  updateRoleStatus = '/sys/role/status',
  RolePageList = '/sys/role/page',

  //菜单相关
  MenuList = '/sys/menu/tree/list',
  deleteMenu = '/sys/menu',
  updateMenu = '/sys/menu/update',
  createMenu = '/sys/menu/create',
  getMenuListByRole = '/sys/menu/role',

  //部門相关
  DeptList = '/sys/dept/tree/list',
  DeptRestFul = '/sys/dept',
  getDeptListByRole = '/sys/dept/role',

  //接口相关
  ItfList = '/sys/interface/tree/list',
  ItfPageList = '/sys/interface/page',
  GetAllItfList = '/sys/interface/list',
  InterfaceRestful = '/sys/interface',
  getItfListByRole = '/sys/interface/role',

  //接口分类相关
  InterfaceCateRestful = '/sys/interface/category',
  ItfCateList = '/sys/interface/category/page',
  ItfCateAllList = '/sys/interface/category/list',
}

//账户相关
export const getAccountList = (params: AccountParams) =>
  defHttp.get<AccountListGetResultModel>({ url: Api.AccountList, params });

export const createAccount = (params: AccountParams) =>
  defHttp.post<void>({ url: Api.AccountRestFul, params });

export const updateAccount = (params: AccountParams) =>
  defHttp.put<void>({ url: Api.AccountRestFul, params });

export const deleteAccount = (id: number) =>
  defHttp.delete<void>({ url: Api.AccountRestFul + `/${id}` });

//部门相关
export const getDeptList = (params?: DeptParams) =>
  defHttp.get<DeptListGetResultModel>({ url: Api.DeptList, params });

export const createDept = (params?: DeptParams) =>
  defHttp.post<void>({ url: Api.DeptRestFul, params });

export const updateDept = (params?: DeptParams) =>
  defHttp.put<void>({ url: Api.DeptRestFul, params });

export const deleteDept = (id?: number) =>
  defHttp.delete<void>({ url: Api.DeptRestFul + `/${id}` });

export const getDeptListByRole = (id: number) =>
  defHttp.get<Array<DeptListItem>>({ url: Api.getDeptListByRole + `/${id}` });

//菜单相关
export const getMenuList = (params?: MenuParams) =>
  defHttp.get<MenuListGetResultModel>({ url: Api.MenuList, params });

export const deleteMenu = (id: number) => defHttp.delete<void>({ url: Api.deleteMenu + `/${id}` });

export const updateMenu = (params: MenuParams) =>
  defHttp.put<void>({ url: Api.updateMenu, params });

export const createMenu = (params: MenuParams) =>
  defHttp.post<void>({ url: Api.createMenu, params });

export const getMenuListByRole = (id: number) =>
  defHttp.get<Array<MenuListItem>>({ url: Api.getMenuListByRole + `/${id}` });

//角色相关
export const getRoleListByPage = (params?: RolePageParams) =>
  defHttp.get<RolePageListGetResultModel>({ url: Api.RolePageList, params });

export const getAllRoleList = (params?: RoleParams) =>
  defHttp.get<RoleListGetResultModel>({ url: Api.GetAllRoleList, params });

export const deleteRole = (id: number) => defHttp.delete<void>({ url: Api.RoleRestful + `/${id}` });

export const updateRole = (params: RoleParams) =>
  defHttp.put<void>({ url: Api.RoleRestful, params });

export const updateRoleStatus = (params: RoleParams) =>
  defHttp.put<void>({ url: Api.updateRoleStatus, params });

export const createRole = (params: RoleParams) =>
  defHttp.post<void>({ url: Api.RoleRestful, params });

//接口相关
export const getItfListByPage = (params?: InterfacePageParams) =>
  defHttp.get<InterfacePageListGetResultModel>({ url: Api.ItfPageList, params });

export const getItfList = (params?: InterfaceParams) =>
  defHttp.get<InterfacePageListGetResultModel>({ url: Api.ItfList, params });

export const getAllItfList = (params?: InterfaceParams) =>
  defHttp.get<InterfaceListGetResultModel>({ url: Api.GetAllItfList, params });

export const deleteItf = (id: number) =>
  defHttp.delete<void>({ url: Api.InterfaceRestful + `/${id}` });

export const updateItf = (params: InterfaceParams) =>
  defHttp.put<void>({ url: Api.InterfaceRestful, params });

export const createItf = (params: InterfaceParams) =>
  defHttp.post<void>({ url: Api.InterfaceRestful, params });

export const getItfListByRole = (id: number) =>
  defHttp.get<Array<InterfaceListItem>>({ url: Api.getItfListByRole + `/${id}` });

//接口分类
export const getItfCateList = (params?: InterfaceParams) =>
  defHttp.get<InterfaceCatePageListGetResultModel>({ url: Api.ItfCateList, params });

export const getAllItfCateList = () =>
  defHttp.get<InterfaceCateListGetResultModel>({ url: Api.ItfCateAllList });

export const deleteCateItf = (id: number) =>
  defHttp.delete<void>({ url: Api.InterfaceCateRestful + `/${id}` });

export const updateCateItf = (params: InterfaceCateParams) =>
  defHttp.put<void>({ url: Api.InterfaceCateRestful, params });

export const createCateItf = (params: InterfaceCateParams) =>
  defHttp.post<void>({ url: Api.InterfaceCateRestful, params });
